use "port-pairs-data2", clear

egen gid = group(A_acid D_acid)
tsset gid post

global m "teu"
gen lnt = log(traffic_$m)
gen lnh = log(travel_hs)
gen lnb = log(boat_size_$m)
gen cap = boat_size_$m*freq
gen lnf = log(freq)
gen lnu = log(traffic_$m/(freq*boat_size_$m))		// Utilization 

replace XPanama=0 if XPanama==.

* Winsorize data
gen dlnt = d.lnt
sum dlnt, det
drop if (dlnt>r(p99)|dlnt<r(p1)) & dlnt!=.

global w "[w=traffic_$m]"
global vce "vce(robust)"
global c "A_lon A_lat D_lon D_lat lnpcD lnpcA"

*********************
* 3 margins: Avg boat size, frequency and avg. utilization
* The coefficients sum up to ln(t)
*********************


* Boat size
reg d.lnb XPanama $w if d.lnt!=., $vce
reghdfe d.lnb XPanama $c if d.lnt!=. $w, absorb(D_country A_country) $vce
reghdfe d.lnb XPanama if d.lnt!=. $w, absorb(D_acid A_acid) $vce

* Utilization
reg d.lnu XPanama $w if d.lnt!=., $vce
reghdfe d.lnu XPanama $c if d.lnt!=. $w, absorb(D_country A_country) $vce
reghdfe d.lnu XPanama if d.lnt!=. $w, absorb(D_acid A_acid) $vce

* Frequency
reg d.lnf XPanama $w if d.lnt!=., $vce
reghdfe d.lnf XPanama $c if d.lnt!=. $w, absorb(D_country A_country) $vce
reghdfe d.lnf XPanama if d.lnt!=. $w, absorb(D_acid A_acid) $vce

* Time
reg d.lnh XPanama $w if d.lnt!=., $vce
reghdfe d.lnh XPanama $c if d.lnt!=. $w, absorb(D_country A_country) $vce
reghdfe d.lnh XPanama if d.lnt!=. $w, absorb(D_acid A_acid) $vce

* Traffic
reg d.lnt XPanama $w if d.lnt!=., $vce
reghdfe d.lnt XPanama $c if d.lnt!=. $w, absorb(D_country A_country) $vce
reghdfe d.lnt XPanama if d.lnt!=. $w, absorb(D_acid A_acid) $vce

